package com.nanfang51g3.ckz.ui.registered;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.nanfang51g3.ckz.R;
import com.nanfang51g3.ckz.application.CkzApplication;
import com.nanfang51g3.ckz.ui.base.IPresenter;
import com.nanfang51g3.ckz.ui.base.Base2Activity;
import com.nanfang51g3.ckz.utils.AppManager;
import com.nanfang51g3.ckz.utils.ButtonUtils;
import com.nanfang51g3.ckz.utils.EasyToast;
import com.nanfang51g3.ckz.widget.ClearEditText;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * Created by Administrator on 2016/4/13.
 */
public class Registered1Activity extends Base2Activity implements RegisteredContract.View {


    RegisteredContract.RegisteredActionsListener registeredActionsListener;
    @Bind(R.id.index_tv_right_title)
    TextView indexTvRightTitle;
    @Bind(R.id.cet_registered1_phone)
    ClearEditText cetRegistered1Phone;

    @Override
    public IPresenter getPresenter() {
        return null;
    }
    @Override
    public int getContentView() {
        return R.layout.registered1;
    }

    @Override
    public boolean isShowLeftIcon() {
        return true;
    }

    @Override
    public boolean isShowRightIcon() {
        return false;
    }

    @Override
    public int setLeftIcon() {
        return R.mipmap.ic_accounting_left;
    }

    @Override
    public int setRightIcon() {
        return 0;
    }

    @Override
    public int showTitle() {
        return R.string.str_phone;
    }

    @Override
    public void onClickLeft(View v) {
        AppManager.getAppManager().finishActivity(this);
    }

    @Override
    public void onClickRight(View v) {

    }

    @Override
    public void showProgress() {
        super.showPro(R.string.str_progress_login);
    }

    @Override
    public void dismissProgress() {
        super.dismissPro();
    }

    @Override
    public void startShowView() {
        String phone = cetRegistered1Phone.getText().toString().trim();
        startActivity(new Intent(Registered1Activity.this, Registered2Activity.class).putExtra("phone", phone));
    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    public void showMessage(String message) {
        EasyToast.showShort(this, message);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        registeredActionsListener = DaggerRegisteredContractComponent
                .builder()
                .appComponent(CkzApplication.getAppComponent())
                .registeredPresenterModule(new RegisteredPresenterModule(this))
                .build().getRegisteredPresenter();
        Log.i("TAG", registeredActionsListener == null ? "registeredActionsListener==null" : "registeredActionsListener!=null");
        indexTvRightTitle.setVisibility(View.VISIBLE);
        indexTvRightTitle.setText(getResources().getString(R.string.str_next));
        indexTvRightTitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (!ButtonUtils.isFastDoubleClick(R.id.index_tv_right_title)) {
                    //写你相关操作即可
                    String phone = cetRegistered1Phone.getText().toString().trim();
                    /**
                     * @see  RegisteredPresenter#getRegisteredCode(String, boolean)
                     */
                    registeredActionsListener.getRegisteredCode(phone,true);
                }
            }
        });
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);//解除绑定，官方文档只对fragment做了解绑
    }
}
